/*
 * Author: Christopher Yeaman
 * Project: ManuscriptPR
 * Class: TCSS 360, Tenenberg
 * Date: Autumn 2011
 */

package document;

import java.util.ArrayList;
import java.util.List;

import user.Conference;
import user.User;

/**
 * The manuscript class represents a document that is stored in the persistent store
 * and can be accessed through a given file path. The Manuscript will retain information
 * on it's title, the number of and who the reviewers are for this document, the
 * status of the document, and the list of reviews.
 * 
 * @author Christopher Yeaman
 * @author Tony Butterfield (getTitle() accessor)
 * @version 12/2/2011
 */
public class Manuscript extends AbstractDocument
{

  /**
   * The number of reviews attached to the manuscript.
   */
  private List<User> my_list_of_reviewers;

  /**
   * The status of the manuscript.
   */
  private int my_status;

  /**
   * The list of reviews assigned to this manuscript.
   */
  private ReviewCollection my_list_of_reviews;

  /**
   * The title of the manuscript.
   */
  private String my_title;
  
  /** the conference the manuscript was submitted to. */
  private Conference my_conference;

  /**
   * Constructor for the Manuscript class.
   * 
   * @param the_user The author of the manuscript.
   * @param the_title The title of the manuscript.
   * @param the_conference The conference in which the manuscript is associated.
   * @param the_file_name The name of the file.
   */
  public Manuscript(final User the_user, final String the_title, 
                    final Conference the_conference, final String the_file_name)
  {
    super(the_user, the_file_name);
    my_list_of_reviewers = new ArrayList<User>();
    my_title = the_title;
    my_conference = the_conference;
    my_status = 0;
    my_list_of_reviews = new ReviewCollection();
  }

  /**
   * Adds a user as a reviewer assigned to the manuscript.
   * 
   * @param the_user The author of the review to be added.
   */
  public void addReviewer(final User the_user)
  {
    my_list_of_reviewers.add(the_user);
  }

  /**
   * Subtracts from the total number of reviews assigned to the manuscript.
   * 
   * @param the_user The author of the review to be removed.
   */
  public void removeReviewer(final User the_user)
  {
    my_list_of_reviewers.remove(the_user);
  }

  /**
   * Add a completed review document to a manuscript.
   * 
   * @param the_user The author of the review.
   * @param the_review The review to be connected to the manuscript.
   */ 
  public void addReviewDoc(final User the_user, final Review the_review)
  {
    my_list_of_reviews.addReview(the_user, the_review);
  }
  
  /**
   * get the manuscript's title.
   * @return String the title
   */
  public String getTitle()
  {
    return my_title;
  }
  
  /**
   * get the conference.
   * @return Conference the conference
   */
  public Conference getConference()
  {
    return my_conference;
  }

  /**
   * Retrieves the collection of reviews attached to the manuscript.
   * 
   * @return The collection of reviews.
   */
  public ReviewCollection getReviews()
  {
    return my_list_of_reviews;
  }
  
  /**
   * returns a List<Review> of all reviews for this manuscript.
   * @return List<Review> containing reviews
   */
  public List<Review> getAllReviews()
  {
    return new ArrayList<Review>(my_list_of_reviews.getAllReviews());
  }

  /**
   * Returns the number reviews assigned to this manuscript.
   * 
   * @return the number of reviews.
   */
  public int getNumberOfReviewers()
  {
    return my_list_of_reviewers.size();
  }

  /**
   * Sets the status of the manuscript. Value greater than zero means that the 
   * manuscript has been accepted. A value less than zero means the manuscript 
   * has been rejected. A value of zero means that no decision has been made on 
   * the manuscript.
   * 
   * @param the_status The current status of the manuscript.
   */
  public void setStatus(final int the_status)
  {
    my_status = the_status;
  }

  /**
   * Gets the status of the current manuscript. Value greater than zero means that 
   * the manuscript has been accepted. A value less than zero means the manuscript 
   * has been rejected. A value of zero means that no decision has been made on the 
   * manuscript.
   * 
   * @return The current status of the manuscript.
   */
  public int getStatus()
  {
    return my_status;
  }

  /**
   * Grabs the text of the manuscript and returns it as a string.
   * 
   * @return the text of the manuscript.
   */
  public String getText()
  {
    return getText("PersistentStore/" + super.getFileName());
  }
}
